package com.ruoyi.utils.login;



import java.util.UUID;

/**
 * 描述：UUID工具类 <br>
 */
public class UUIDUtil {
	
	private UUIDUtil() {}

	public static void main(String[] args) {
		System.out.println(getUUID()+"--"+getUUID().length());
		System.out.println("HHDZ181101165620885R19352".length());
		System.out.println(getSHDZ()+"--"+getSHDZ().length());
	}
	
	/**
	 * 获取UUID，去除“-”
	 * @return {@link String} UUID
	 */
	public static final String getUUID() {
		return UUID.randomUUID().toString().replace("-", "");
	}


	//日志LOGID
	public static final String getLog()
	{
		return "LOG"+ DateUtil.getNow().replaceAll("\\D","")+UUID.randomUUID().toString().replace("-", "").substring(25);
	}

	//购物车gwcid
	public static final String getgwcid()
	{
		return "GWC"+ DateUtil.getNow().replaceAll("\\D","")+UUID.randomUUID().toString().replace("-", "").substring(25);
	}

	//订单OID
	public static final String getOrder()
	{
		return "D"+DateUtil.getTime()+UUID.randomUUID().toString().replace("-", "").substring(26);
	}

	//收藏商品SCID(未启用)
	public static final String getSc()
	{
		return "SC"+DateUtil.getTime1()+UUID.randomUUID().toString().replace("-", "").substring(26);
	}


	//收货地址ID
	public static final String getSHDZ()
	{
		return "HHDZ"+DateUtil.getTime1()+UUID.randomUUID().toString().replace("-", "").substring(24);
	}


	/**
	 * 检验字符是否是正整数
	 *
	 * @param str
	 * @return
	 */
	public static boolean isPosInt(String str) {
		if (str == null || "".equals(str.trim()))
			return false;
		for (int i = str.length(); --i >= 0;) {
			if (!Character.isDigit(str.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 隐藏姓名
	 *
	 * @param name
	 * @return
	 */
	public static String hideName(String name) {
		String str = "**";
		StringBuilder sb = new StringBuilder(name);
		int i = 0;
		if (name.length() == 2) {
			i = 2;
		} else {
			i = name.length() - 1;
		}
		sb.replace(1, i, str);
		return sb.toString();
	}

	/**
	 * 隐藏手机号中间四位
	 *
	 * @param phone
	 * @return
	 */
	public static String hidePhoneNum(String phone) {
		return phone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
	}

	/**
	 * 隐藏快递地址
	 *
	 * @param address
	 * @return
	 */
	public static String hideAddress(String address) {
		String str = "****";
		StringBuilder sb = new StringBuilder(address);
		int i = 0;
		int j = 0;
		if (address.length() <= 9) {
			i = 9;
		} else {
			i = address.length() - 3;
		}
		if (address.length() < 6) {
			j = address.length() - address.length() + 1;
		} else {
			j = 6;
		}
		sb.replace(j, i, str);
		return sb.toString();
	}
}
